package com.twu.biblioteca;

/**
 * Created by sravanns on 09/06/14.
 */
/* Job: represents ability to check out a book*/
public class CheckoutBook implements MenuAction {

   private Library library;
    private UserInterface UIApplication;

    @Override
    public String toString() {
        return "Check Out Book";
    }

    public CheckoutBook(Library obj, UserInterface ui) {
        library = obj;
        UIApplication =ui;
    }

    @Override
    public Result performAction(String user) {
        UIApplication.display("Enter Book Name");
        String input = UIApplication.acceptTitle();
        Result result=new Result();

        Book book = library.getBookFromCatalogue(input);
        if (book != null) {
            if (library.checkOutBook(book,user)) {

                result.setResult("Thank you! Enjoy the book",true);

            } else
                result.setResult("That book is not available. might be checked out already",false);

        }
        else
         result.setResult("That book is not available in Library. please consider checking the spelling",false);
        return result;
    }

}

